﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace ServicioMicro
{
    public class ServicioConsultorMicro : IService
    {

        public List<Micro> ObtenerMicrosDeLaEmpresaConId(int idEmpresa)
        {
            List<Micro> microsADevolver = new List<Micro>();
           
            DataSetMicro.microDataTable tablaConRegistros = CAD_Micro.ObtenerMicrosDeLaEmpresaConId(idEmpresa);
            if (EstaVaciaLaTabla(tablaConRegistros))
            {
                return microsADevolver;
            }

            foreach (DataSetMicro.microRow registro in tablaConRegistros.Rows)
            {
                Micro micro = ArmarMicroAPartirDeUnRegistro(registro);
                microsADevolver.Add(micro);
            }

            return microsADevolver;
        }


        private Micro ArmarMicroAPartirDeUnRegistro(DataSetMicro.microRow registro)
        {
            Micro microADevolver = null;
            if (registro == null)
            {
                return microADevolver;
            }

            microADevolver = new Micro();
            microADevolver.Id = registro.id;
            microADevolver.Codigo = registro.Codigo;
            microADevolver.Destino_id = registro.destino_id;
            microADevolver.Empresa_id = registro.empresa_id;

            return microADevolver;
        }

        private bool EstaVaciaLaTabla(DataSetMicro.microDataTable tabla)
        {
            return (tabla.Rows.Count == 0);
        }

    }
}
